package xyz.riceball.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import xyz.riceball.common.EnableRbCommon;
import xyz.riceball.develop.EnableRbDevelop;
import xyz.riceball.generator.EnableRbGenerator;
import xyz.riceball.job.EnableRbJob;
import xyz.riceball.security.EnableRbSecurity;
import xyz.riceball.usercore.EnableRbUserCore;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * <p>
 * 自动扫描
 * </p>
 *
 * @author xiaovcloud
 * @since 2022/4/23 22:49
 */
@ComponentScans({
        @ComponentScan(value = "xyz.riceball.api"),
})
@Slf4j
@EnableRbDevelop
@EnableRbGenerator
@EnableRbJob
@EnableRbSecurity
@EnableRbUserCore
@EnableRbCommon
public class AutoImportRiceBall {
    @Resource
    ServerProperties serverProperties;

    @PostConstruct
    public void startLog() {
        //do nothing...
        log.info("请登陆后台 {} 来操作RiceBall框架", getUrl());
    }

    public String getUrl() {
        InetAddress address = null;
        try {
            address = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return "http://" + address.getHostAddress() + ":" + this.serverProperties.getPort() + "/rb/web";
    }
}
